/*
 SGSortingGameViewController.h
 Date Created: Feburary 24, 2010
 
 Authors: Karanvir Gill <viper1029@gmail.com>
				  Frank Lau <flaua@sfu.ca>
          Karol Krizka <kkrizka@gmail.com>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import <UIKit/UIKit.h>
#import "SGRecyclableItem.h"
#import "SGSortingGameLevel.h"

#import "../profilemngt/PMProfile.h"

@interface SGSortingGameViewController : UIViewController {
  // UI References
  IBOutlet UILabel *levelScoreLabel;
  IBOutlet UILabel *totalScoreLabel;
  IBOutlet UILabel *livesLeftLabel;
  IBOutlet UILabel *levelLabel;

  // Information about the current game
  NSUInteger score;
  NSUInteger livesLeft;
  bool tutorialModeOn;
  NSMutableArray *unexplainedItemTypes; // Used for tutorial mode
  PMProfile *playerProfile; // The profile of the user that is playing the game
  
  // Some statistics
  NSUInteger totalScore;                      //the total game score
  NSUInteger numberOfItemsAlreadyDisplayed;   //the number of items already displayed in the current level
  NSUInteger totalNumberOfItemsToDisplay;     //the  number of items to be displayed in the current level
  NSUInteger droppedInCorrectBin;             //items dropped in the correct bin in the current level
  NSUInteger droppedOutsideCorrectBin;        //items that have not been dropped into a bin, items mistakenly dropped in the garbage bin, and items dropped into the wrong bin
  NSUInteger droppedInsideBin;                //items dropped into the correct and wrong bins
  NSUInteger numDraggedAndDropped;            //every item that has been dragged and dropped
  NSUInteger droppedInWrongBin;               //items mistakenly dropped in the garbage bin, and items dropped into the wrong bin
  NSUInteger currNumberOfItemsProcessed;      //the number of items that have been dragged or dropped in the garbage
  NSUInteger numInGarbage;                    //items dropped into garbage bin
  NSUInteger totalDroppedOutsideCorrectBin;   //number of items dropped outside correct bin in the current level
  NSUInteger totalCorrectlySortedInGame;      //keeps track of all the items that have been correctly sorted in the sorting game
  NSUInteger totalProcessedInGame;            //keeps track of the number of items processed in the game
  float accuracy;
  
  
  // Controls the flow of the game
  NSMutableArray *arrayOfItemsToDisplay;
  NSMutableArray *itemsOnScreen;
  NSMutableArray *binsOnScreen;
  NSUInteger currLevel; //current level in sorting game
  BOOL levelChanged; // Level has been changed, so make sure to reload labels
                     // before view is shown
  
  CGPoint speedOfItems;
  SGSortingGameLevel *sortingGameLevel;
  
  NSTimer *moveTimer; // Move items across the screen
  NSTimer *createTimer; // Create new items
	
}

@property (nonatomic,retain) PMProfile *playerProfile;
@property (nonatomic,retain) SGSortingGameLevel *sortingGameLevel;
@property (nonatomic,readonly) NSUInteger livesLeft;
@property (nonatomic,retain) IBOutlet UILabel *levelScoreLabel;
@property (nonatomic,retain) IBOutlet UILabel *totalScoreLabel;
@property (nonatomic,retain) IBOutlet UILabel *livesLeftLabel;
@property (nonatomic,retain) IBOutlet UILabel *levelLabel;

/**
 * Constructor for sorting game view controller which initializes the 
 * level number to be 1
 */
- (SGSortingGameViewController*)init;

/**
 * Stops the timers that update the game. This effectively pauses the game,
 * but does not change the UI.
 */
- (void)stopTimers;

/**
 * Starts the timers, so the game continues progressing.
 */
- (void)startTimers;


/**
 * Pauses the game and shows the SGPauseViewController
 */
- (IBAction)showPauseMenu:(id)sender;

/**
 * Turns tutorial mode on/off for the current player
 */
- (IBAction)tutorialModeOnOff:(id)sender;

/**
 * Creates a recyclable item and shows it on display. It will only create items 
 * if numberOfItemsAlreadyDisplayed is less than totalNumberOfItemsToDisplay.
 * The recyclable type to create is determined by arrayOfItemsToDisplay.
 */
- (void)createItem;

/**
 * Moves all the objects on the screen down by a certain number of pixels 
 * (determined by the level). Checks if the objects are over a bin, in the
 * garbage or anywhere else on the screen. If an item have been picked up 
 * then it will disapper when dropped, and points will only be given if its 
 * dropped in the correct bin.
 */
- (void)moveItems;

/**
 * Used to place the bins on the screen. Adds the created bins to the
 * binsOnScreen array.
 */
- (void)drawBins;

/**
 *Reload view for the correct level
 */
- (void) reloadView;

/**
 * release items that will be reloaded 
 */
- (void) releaseBeforeReload;

/**
 *show level Summary Screen
 */
- (void)showLevelSummary;

/**
 *show end game screen
 */
- (void)showEndGame;

 
@end
